var util = require('../../../../utils/util.js');
class Movie {
  constructor(url) {
    this.url = url;
  }
  getMovieData(cb) {
    this.cb = cb;
    util.http(this.url, this.processDoubanData.bind(this));
  }

  processDoubanData(data) {
    if (!data) {
      return;
    }
    var director = {
      avatar: data.director[0].data[0].name,
      name: data.director[0].data[0].name,
      id: data.director[0].data[0].id
    }
    var movie = {
      movieImg: data.data[0].poster,
      country: data.data[0].country,
      title: data.data[0].name,
      originalTitle: data.originalName,
      wishCount: data.duration,
      commentCount: data.doubanVotes,
      year: data.year,
      genres: data.data.genre,
      // genres:data.data.genre.join("、"),
      stars: util.convertToStarsArray(data.doubanRating),
      score: data.doubanRating,
      director: director,
      casts: util.convertToCastString(data.actor),
      castsInfo: util.convertToCastInfos(data.actor),
      summary: data.data.description
    }
    this.cb(movie);
  }
}

export{Movie}